/*     */ package com.qmsk.business.member.memberWx.controller;
/*     */ 
/*     */ import com.qmsk.business.manage.cust.dao.CustDAO;
/*     */ import com.qmsk.business.manage.cust.dao.CustShopDAO;
/*     */ import com.qmsk.business.manage.mpCity.dao.MpCityDAO;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberCouponBill.dao.MemberCouponBillDao;
/*     */ import com.qmsk.business.member.memberCouponDetail.dao.MemberCouponDetailDao;
/*     */ import com.qmsk.business.member.memberCouponRule.dao.MemberCouponRuleDao;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberIntegralRule.dao.MemberIntegralRuleDAO;
/*     */ import com.qmsk.business.member.memberLevel.dao.MemberLevelDAO;
/*     */ import com.qmsk.business.member.memberWx.dao.MemberWxDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.weixin.customMenu.customer.CustomerInfo;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.qmsk.business.weixin.customMenu.wxMapUtils.WxMapUtils;
/*     */ import com.utils.basic.CDateTimeComm;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadManyRows;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Random;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/memberWx"})
/*     */ public class MemberWxController
/*     */ {
/*  57 */   private static final Logger logger = Logger.getLogger(MemberWxController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberWxDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private MpCityDAO mpCityDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustDAO custDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustShopDAO custShopDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberLevelDAO memberLeveldao;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponRuleDao couponRuleDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponBillDao memberCouponBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCouponDetailDao memberCouponDetailDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralRuleDAO memberIntegralRuleDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO integralDetailDAO;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 118 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 120 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/* 121 */         nPageSize);
/* 122 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 124 */       logger.error(e);
/* 125 */       ResponseUtils.setErrorMsgResponse(
/* 126 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/isMemberOfCust"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void get(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 141 */     String openId = RequestUtils.getString(request, "openId");
/* 142 */     Long shopId = RequestUtils.getLong(request, "shopId");
/*     */     try {
/* 144 */       boolean isMember = this.custDao.getIsMemberOfCust(shopId, openId);
/* 145 */       if (isMember) {
/* 146 */         ResponseUtils.setSuccessResponse(response);
/* 147 */         return;
/*     */       }
/* 149 */       ResponseUtils.setErrorMsgResponse(
/* 150 */         RequestUtils.getFindDataErrorMessage(request), 
/* 151 */         response);
/*     */     }
/*     */     catch (SQLException e) {
/* 154 */       logger.error(e);
/* 155 */       ResponseUtils.setErrorMsgResponse(
/* 156 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 174 */       int nResult = 0;
/* 175 */       Long shopId = RequestUtils.getLong(request, "shopId");
/* 176 */       GsonHeadOneRow r = GsonHeadOneRow.jsonStrToObject(
/* 177 */         RequestUtils.getStringOfData(request));
/* 178 */       if (r != null) {
/* 179 */         String openId = (String)r.getValueOfName("openId");
/* 180 */         String mp = (String)r.getValueOfName("mp");
/* 181 */         Long custId = this.memberDao.getIsMemberRgNew(openId, shopId);
/* 182 */         String custName = (String)r.getValueOfName("custName");
/* 183 */         logger.error("********openId" + openId);
/* 184 */         logger.error("********mp" + custName);
/* 185 */         if (custId.longValue() > 0L) {
/* 186 */           ResponseUtils.setErrorMsgResponse("您已经申请过会员", response);
/* 187 */           return;
/*     */         }
/* 189 */         if ((shopId != null) && (StringUtils.isNotEmpty(openId))) {
/* 190 */           if (this.memberDao.getIsMemberRgNew(openId, shopId).longValue() <= 0L) {
/* 191 */             logger.error("重新注册");
/* 192 */             nResult = getGsonOfLevelid(nResult, custName, r, openId, 
/* 193 */               mp, shopId, request, response);
/*     */           } else {
/* 195 */             logger.error("修改注册");
/*     */ 
/* 197 */             nResult = updateCustInfoOfmember(mp, custName, openId, shopId);
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 202 */         if (nResult <= 0) {
/* 203 */           DbConnection.rollback();
/* 204 */           ResponseUtils.setErrorMsgResponse("申请失败！", response);
/* 205 */           return;
/*     */         }
/* 207 */         int count = this.dao.getMemberCount();
/* 208 */         DbConnection.commit();
/* 209 */         ResponseUtils.toGsonEbRst(new String[] { "count" }, 
/* 210 */           new Object[] { Integer.valueOf(count) }, response);
/*     */       }
/*     */     } catch (Exception e) {
/* 213 */       DbConnection.rollback();
/* 214 */       logger.error(e);
/* 215 */       ResponseUtils.setErrorMsgResponse(
/* 216 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 217 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private int updateCustInfoOfmember(String mp, String custName, String openId, Long shopId) throws SQLException {
/* 222 */     int shu = 0;
/*     */ 
/* 224 */     logger.error("**********修改******************");
/* 225 */     Long custId = this.memberDao.getIsMemberRgNew(openId, shopId);
/* 226 */     if (custId.longValue() > 0L) {
/* 227 */       GsonHeadOneRow g = new GsonHeadOneRow(new String[] { "mp", "name" }, new Object[] { mp, custName });
/* 228 */       g.addHeadData("id", custId);
/* 229 */       shu = this.custDao.updateJsonOneRow(g);
/* 230 */       if (shu > 0) {
/* 231 */         logger.error("**********修改custDao成功******************");
/* 232 */         Integer validDay = null;
/* 233 */         Long memberId = this.memberDao.getMemberId(custId);
/* 234 */         if (memberId.longValue() > 0L) {
/* 235 */           GsonHeadOneRow rowMemberLevel = null;
/* 236 */           Long levelId = this.dao.selectSqlOfDefaultParamsShop(shopId, 0);
/* 237 */           Double discount = null;
/* 238 */           if ((levelId != null) && (levelId.longValue() > 0L)) {
/* 239 */             rowMemberLevel = this.memberLeveldao.getGsonOfLevelId(levelId);
/* 240 */             logger.error("**********修改rowMemberLevel******************");
/*     */           } else {
/* 242 */             logger.error("会员级别信息获取失败");
/* 243 */             return 0;
/*     */           }
/* 245 */           GsonHeadOneRow gMember = null;
/* 246 */           if (rowMemberLevel != null) {
/* 247 */             gMember = new GsonHeadOneRow(new String[0], new Object[0]);
/* 248 */             validDay = ObjectComm.objectToInteger(rowMemberLevel.getValueOfName("ValidDay"));
/* 249 */             Date crTime = new Date();
/* 250 */             if (validDay.intValue() <= 0)
/* 251 */               gMember.autoAddHeadData("ValidDateTime", 
/* 252 */                 CDateTimeComm.getAddYear(crTime, 
/* 253 */                 100));
/*     */             else {
/* 255 */               gMember.autoAddHeadData("ValidDateTime", 
/* 256 */                 CDateTimeComm.getAddDay(crTime, 
/* 257 */                 validDay.intValue()));
/*     */             }
/* 259 */             discount = ObjectComm.objectToDouble(rowMemberLevel.getValueOfName("discount"));
/* 260 */             gMember.addHeadData(new String[] { "ValidDay", "DisCount", "MemberCardNo", "LevelID", "MemberID", "ShopID" }, new Object[] { validDay, discount, mp, levelId, memberId, shopId });
/*     */           }
/* 262 */           shu = this.shopMemberDAO.updateOneRowOfPkHead(
/* 263 */             gMember, new String[] { "MemberID", "ShopID" });
/*     */ 
/* 265 */           GsonHeadOneRow memberRuleRow = this.memberIntegralRuleDAO.selectgzInfo(shopId, levelId, "会员注册");
/* 266 */           Integer intAmt = Integer.valueOf(0);
/* 267 */           if ((memberRuleRow != null) && (shu > 0)) {
/* 268 */             intAmt = ObjectComm.objectToInteger(memberRuleRow.getValueOfName("FixedIntegral"));
/* 269 */             if (intAmt.intValue() > 0) {
/* 270 */               Long ruId = (Long)memberRuleRow.getValueOfName("RuleID");
/* 271 */               String billNo = this.memberIntegralBillDao.getMaxBillNo(shopId);
/* 272 */               shu = this.memberIntegralBillDao.insertIntegralBill(memberId, shopId, billNo, ruId, intAmt, "会员注册", new Date(), null, 1, "wx", "会员注册");
/* 273 */               if (shu > 0) {
/* 274 */                 Long billId = this.memberIntegralBillDao.getLastId();
/* 275 */                 shu = this.integralDetailDAO.insertBusBillDtialInAmt(memberId, 
/* 276 */                   shopId, intAmt, Integer.valueOf(0), billId);
/*     */               }
/* 278 */               StringBuffer sb = new StringBuffer();
/* 279 */               sb.append("尊敬的" + custName + ",您已经通过会员审核。");
/* 280 */               if ((intAmt.intValue() > 0) && (shu > 0)) {
/* 281 */                 sb.append("本次获得" + intAmt + "积分。");
/* 282 */                 this.shopMemberDAO.updateBillMemberIntAmt(memberId, intAmt, shopId);
/*     */               }
/* 284 */               WeiXinUtil.sendTextMessageOfMain(sb.toString(), openId);
/* 285 */               return shu;
/*     */             }
/* 287 */             logger.error("无可添加的积分");
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 293 */     return shu;
/*     */   }
/*     */ 
/*     */   private List<Integer> getIndexListOfRandom(Integer dataLength, Integer radNum)
/*     */   {
/* 324 */     if (((dataLength == null) && (radNum == null)) || ((dataLength != null) && 
/* 325 */       (dataLength.intValue() <= 0)) || (
/* 325 */       (radNum != null) && (radNum.intValue() <= 0))) {
/* 326 */       return null;
/*     */     }
/*     */ 
/* 329 */     List IndexList = new ArrayList();
/* 330 */     int size = 0;
/* 331 */     int length = dataLength.intValue();
/* 332 */     if (radNum.intValue() >= dataLength.intValue())
/* 333 */       size = dataLength.intValue();
/*     */     else {
/* 335 */       size = radNum.intValue();
/*     */     }
/*     */ 
/* 338 */     Random random = new Random();
/* 339 */     int count = size;
/* 340 */     boolean isExit = true;
/* 341 */     for (int i = 0; i <= count; ++i) {
/* 342 */       int index = random.nextInt(length);
/* 343 */       if (IndexList.size() == 0) {
/* 344 */         IndexList.add(Integer.valueOf(index));
/*     */       } else {
/* 346 */         if (size == IndexList.size()) {
/*     */           break;
/*     */         }
/*     */ 
/* 350 */         for (int j = 0; j < IndexList.size(); ++j) {
/* 351 */           int randIndex = ((Integer)IndexList.get(j)).intValue();
/* 352 */           if (randIndex == index) {
/* 353 */             isExit = false;
/* 354 */             break;
/*     */           }
/* 356 */           isExit = true;
/*     */         }
/*     */ 
/* 359 */         if ((isExit) && (size > IndexList.size()))
/* 360 */           IndexList.add(Integer.valueOf(index));
/*     */         else {
/* 362 */           ++count;
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 367 */     return IndexList;
/*     */   }
/*     */ 
/*     */   private int insertMemberCoupon(Long memberId) throws SQLException
/*     */   {
/* 372 */     List couponRuleIndexList = new ArrayList();
/* 373 */     GsonHeadManyRows g = this.couponRuleDao.getCouponRuleList();
/* 374 */     int nResult = 0;
/* 375 */     if ((g != null) && (g.isExistsData())) {
/* 376 */       couponRuleIndexList = getIndexListOfRandom(Integer.valueOf(g.getDataLength()), Integer.valueOf(5));
/* 377 */       if ((couponRuleIndexList != null) && (couponRuleIndexList.size() > 0)) {
/* 378 */         ParserDataSetJson billp = new ParserDataSetJson();
/* 379 */         billp.setListInsertRows(new ArrayList());
/* 380 */         ParserDataSetJson dtP = new ParserDataSetJson();
/* 381 */         dtP.setListInsertRows(new ArrayList());
/* 382 */         for (int i = 0; i < couponRuleIndexList.size(); ++i) {
/* 383 */           int coupIndex = ((Integer)couponRuleIndexList.get(i)).intValue();
/* 384 */           String[] billHeads = { "MemberID", "RuleID", 
/* 385 */             "ShopID", "CouponNo", "FaceValue", "crFTime", 
/* 386 */             "crFMan", "Status", "BillFrom", "CouponCount" };
/* 387 */           String ruleFlag = (String)g.getValueOfName("RuleFlag", 
/* 388 */             coupIndex);
/* 389 */           Long ruleId = ObjectComm.objectToLong(g.getValueOfName(
/* 390 */             "RuleID", coupIndex));
/* 391 */           Long shopId = ObjectComm.objectToLong(g.getValueOfName(
/* 392 */             "ShopID", coupIndex));
/* 393 */           Double faceValue = ObjectComm.objectToDouble(g
/* 394 */             .getValueOfName("FaceValue", coupIndex));
/* 395 */           String couponNo = null;
/* 396 */           if (StringUtils.isNotEmpty(ruleFlag)) {
/* 397 */             couponNo = this.couponRuleDao.getConponMaxNo(ruleFlag);
/*     */           }
/* 399 */           Object[] billDatas = { memberId, ruleId, 
/* 400 */             shopId, couponNo, faceValue, new Date(), "wx", Integer.valueOf(0), 
/* 401 */             "wx赠送", Integer.valueOf(1) };
/* 402 */           GsonHeadOneRow billRow = new GsonHeadOneRow(billHeads, 
/* 403 */             billDatas);
/* 404 */           if (billRow.isExistsData()) {
/* 405 */             billp.getListInsertRows().add(billRow);
/*     */           }
/*     */ 
/* 410 */           String[] dtHeads = { "MemberID", "ShopID", 
/* 411 */             "CouponNo", "FaceValue", "GrantDate", "EffectDate", 
/* 412 */             "UneffectDate", "Status", "GetMode", "CouponCount" };
/* 413 */           Object[] dtDatas = { memberId, shopId, 
/* 414 */             couponNo, faceValue, new Date(), 
/* 415 */             g.getValueOfName("EffectDate", coupIndex), 
/* 416 */             g.getValueOfName("UneffectDate", coupIndex), Integer.valueOf(0), 
/* 417 */             "wx赠送", Integer.valueOf(1) };
/* 418 */           GsonHeadOneRow dtRow = new GsonHeadOneRow(dtHeads, dtDatas);
/* 419 */           if (dtRow.isExistsData()) {
/* 420 */             dtP.getListInsertRows().add(dtRow);
/*     */           }
/*     */         }
/* 423 */         if (billp.getListInsertRows().size() > 0) {
/* 424 */           nResult = this.memberCouponBillDao.applyUpdates(billp);
/* 425 */           if (nResult > 0) {
/* 426 */             nResult += this.memberCouponDetailDao.applyUpdates(dtP);
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 431 */     return nResult;
/*     */   }
/*     */ 
/*     */   private int getGsonOfLevelid(int nResult, String custName, GsonHeadOneRow r, String openId, String mp, Long shopId, HttpServletRequest request, HttpServletResponse response)
/*     */     throws SQLException
/*     */   {
/* 438 */     Long memberId = null;
/* 439 */     Long custId = null;
/* 440 */     Integer intAmt = Integer.valueOf(0);
/* 441 */     GsonHeadOneRow rowMemberLevel = null;
/* 442 */     Long levelId = this.dao.selectSqlOfDefaultParamsShop(shopId, 0);
/* 443 */     Date crTime = new Date();
/* 444 */     if (levelId != null) {
/* 445 */       rowMemberLevel = this.memberLeveldao.getGsonOfLevelId(levelId);
/*     */     }
/* 447 */     if ((levelId != null) && (rowMemberLevel != null) && 
/* 448 */       (rowMemberLevel.isExistsData())) {
/* 449 */       custId = this.custDao.getUserIdOfMp(mp);
/* 450 */       if ((shopId.longValue() > 0L) && (custId.longValue() <= 0L)) {
/* 451 */         CustomerInfo c = WxMapUtils.getCustInfoOfOpenId(openId);
/* 452 */         String imageUrl = null;
/* 453 */         if (c != null) {
/* 454 */           imageUrl = c.getHeadimgurl();
/*     */         }
/* 456 */         GsonHeadOneRow rowCustomer = new GsonHeadOneRow(new String[] { 
/* 457 */           "name", "Mp", "openId", "password", 
/* 458 */           "Status", 
/* 459 */           "createTime", "CustFrom", "wxCreateTime", "imageUrl" }, 
/* 460 */           new Object[] { custName, 
/* 461 */           mp, openId, 
/* 462 */           "111111", Integer.valueOf(0), crTime, Integer.valueOf(3), crTime, imageUrl });
/* 463 */         nResult = this.custDao.insertGsonHeadOneRow(rowCustomer);
/* 464 */         if (nResult > 0) {
/* 465 */           custId = this.custDao.getLastId();
/* 466 */           if (custId.longValue() > 0L) {
/* 467 */             GsonHeadOneRow s = new GsonHeadOneRow(new String[] { 
/* 468 */               "custId", "shopId" }, new Object[] { custId, 
/* 469 */               shopId });
/* 470 */             nResult = this.custShopDao.insertGsonHeadOneRow(s);
/*     */           }
/*     */ 
/* 473 */           if ((custId.longValue() > 0L) && (nResult > 0)) {
/* 474 */             String[] headMember = { "CustID", 
/* 475 */               "status", "CreateFileTime", "payPwd", 
/* 476 */               "LevelID", "DepositAmount", "IntegralAmount", 
/* 477 */               "ConsumeAmount", "CashCouponAmount", 
/* 478 */               "CouponAmount" };
/* 479 */             Object[] dataMember = { custId, 
/* 480 */               Integer.valueOf(2), crTime, "111111", 
/* 481 */               levelId, Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0) };
/* 482 */             GsonHeadOneRow gMember = new GsonHeadOneRow(headMember, 
/* 483 */               dataMember);
/* 484 */             gMember.encryptHead("payPwd");
/* 485 */             Integer validDay = null;
/* 486 */             Double discount = null;
/* 487 */             if ((levelId != null) && (levelId.longValue() > 0L)) {
/* 488 */               validDay = ObjectComm.objectToInteger(rowMemberLevel.getValueOfName("ValidDay"));
/* 489 */               if (validDay.intValue() <= 0)
/* 490 */                 gMember.autoAddHeadData("ValidDateTime", 
/* 491 */                   CDateTimeComm.getAddYear(crTime, 
/* 492 */                   100));
/*     */               else {
/* 494 */                 gMember.autoAddHeadData("ValidDateTime", 
/* 495 */                   CDateTimeComm.getAddDay(crTime, 
/* 496 */                   validDay.intValue()));
/*     */               }
/* 498 */               discount = ObjectComm.objectToDouble(rowMemberLevel.getValueOfName("discount"));
/* 499 */               gMember.autoAddHeadData("ValidDay", validDay);
/* 500 */               gMember.autoAddHeadData("DisCount", discount);
/*     */             }
/* 502 */             nResult = this.memberDao.insertGsonHeadOneRow(gMember);
/* 503 */             if (nResult > 0) {
/* 504 */               memberId = this.memberDao.getLastId();
/* 505 */               GsonHeadOneRow memberRuleRow = this.memberIntegralRuleDAO.selectgzInfo(shopId, levelId, "会员注册");
/* 506 */               if (memberRuleRow != null) {
/* 507 */                 intAmt = ObjectComm.objectToInteger(memberRuleRow.getValueOfName("FixedIntegral"));
/* 508 */                 if (intAmt.intValue() > 0) {
/* 509 */                   Long ruId = (Long)memberRuleRow.getValueOfName("RuleID");
/* 510 */                   String billNo = this.memberIntegralBillDao.getMaxBillNo(shopId);
/* 511 */                   nResult = this.memberIntegralBillDao.insertIntegralBill(memberId, shopId, billNo, ruId, intAmt, "已关注过客户，账会员户申请赠送", crTime, null, 1, "wx", "已关注过客户，账会员户申请赠送");
/* 512 */                   if (nResult > 0) {
/* 513 */                     Long billId = this.memberIntegralBillDao.getLastId();
/* 514 */                     nResult = this.integralDetailDAO.insertBusBillDtialInAmt(memberId, 
/* 515 */                       shopId, intAmt, Integer.valueOf(0), billId);
/*     */                   }
/*     */                 } else {
/* 518 */                   logger.info("无可添加的积分");
/*     */                 }
/*     */               }
/*     */ 
/* 522 */               if ((nResult > 0) && (memberId.longValue() > 0L)) {
/* 523 */                 Long groupId = 
/* 524 */                   ShopMap.getGroupIdOfShopId(shopId);
/* 525 */                 gMember.delHead(new String[] { "CustID" });
/* 526 */                 gMember.addHeadData(new String[] { "MemberID", 
/* 527 */                   "ShopID", "groupId", "MemberCardNo", 
/* 528 */                   "IsCreateShop" }, new Object[] { 
/* 529 */                   memberId, shopId, groupId, mp, Integer.valueOf(1) });
/* 530 */                 if (intAmt.intValue() > 0) {
/* 531 */                   gMember.autoAddHeadData("IntegralAmount", intAmt);
/*     */                 }
/* 533 */                 nResult = this.shopMemberDAO.insertGsonHeadOneRow(
/* 534 */                   gMember, "crm_shop_member");
/*     */               }
/*     */ 
/*     */             }
/*     */ 
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 545 */         if (nResult > 0) {
/* 546 */           GsonHeadOneRow a = new GsonHeadOneRow(new String[] { 
/* 547 */             "ShopID", "OpenID", "custName", "Mp", "Status", 
/* 548 */             "CreateFileTime" }, new Object[] { shopId, openId, 
/* 549 */             custName, mp, Integer.valueOf(1), crTime });
/* 550 */           nResult = this.dao.insertGsonHeadOneRow(a, "crm_memberapply");
/*     */         }
/* 552 */         StringBuffer sb = new StringBuffer();
/* 553 */         sb.append("尊敬的" + custName + ",您已经通过会员审核。");
/* 554 */         if ((intAmt.intValue() > 0) && (nResult > 0)) {
/* 555 */           sb.append("本次获得" + intAmt + "个邦钻。");
/*     */         }
/* 557 */         WeiXinUtil.sendTextMessageOfMain(sb.toString(), openId);
/* 558 */       } else if ((shopId.longValue() > 0L) && (custId.longValue() > 0L)) {
/* 559 */         String[] heads = { "wxCreateTime", "CustFrom", 
/* 560 */           "openId" };
/* 561 */         Object[] datas = { crTime, Integer.valueOf(3), openId };
/* 562 */         nResult = this.custDao.updateJsonOneRow(
/* 563 */           new GsonHeadOneRow(heads, 
/* 563 */           datas), custId);
/* 564 */         if (nResult > 0) {
/* 565 */           if (this.custShopDao.exitsShopCust(custId, shopId).intValue() == 0) {
/* 566 */             GsonHeadOneRow s = new GsonHeadOneRow(new String[] { 
/* 567 */               "custId", "shopId" }, new Object[] { custId, 
/* 568 */               shopId });
/* 569 */             nResult = this.custShopDao.insertGsonHeadOneRow(s, 
/* 570 */               "crm_shop_customer");
/*     */           }
/* 572 */           memberId = this.memberDao.selectMemberIdOfCustId(custId);
/* 573 */           if ((memberId.longValue() > 0L) && 
/* 575 */             (!(this.shopMemberDAO.existsShopMemberOfId(memberId, 
/* 575 */             shopId)))) {
/* 576 */             GsonHeadOneRow memberRuleRow = this.memberIntegralRuleDAO.selectgzInfo(shopId, levelId, "会员注册");
/* 577 */             if (memberRuleRow != null) {
/* 578 */               intAmt = ObjectComm.objectToInteger(memberRuleRow.getValueOfName("FixedIntegral"));
/* 579 */               if (intAmt.intValue() > 0) {
/* 580 */                 Long ruId = (Long)memberRuleRow.getValueOfName("RuleID");
/* 581 */                 String billNo = this.memberIntegralBillDao.getMaxBillNo(shopId);
/* 582 */                 nResult = this.memberIntegralBillDao.insertIntegralBill(memberId, shopId, billNo, ruId, intAmt, "已关注过客户，账会员户申请赠送", crTime, null, 1, "wx", "已关注过客户，账会员户申请赠送");
/* 583 */                 if (nResult > 0) {
/* 584 */                   Long billId = this.memberIntegralBillDao.getLastId();
/* 585 */                   nResult = this.integralDetailDAO.insertBusBillDtialInAmt(memberId, 
/* 586 */                     shopId, intAmt, Integer.valueOf(0), billId);
/*     */                 }
/*     */               } else {
/* 589 */                 logger.info("无可添加的积分");
/*     */               }
/*     */             }
/*     */ 
/* 593 */             Integer validDay = null;
/* 594 */             Double discount = null;
/* 595 */             Date validDateTime = null;
/* 596 */             if ((levelId != null) && (levelId.longValue() > 0L)) {
/* 597 */               validDay = ObjectComm.objectToInteger(rowMemberLevel.getValueOfName("ValidDay"));
/* 598 */               if (validDay.intValue() <= 0)
/* 599 */                 validDateTime = CDateTimeComm.getAddYear(
/* 600 */                   crTime, 100);
/*     */               else {
/* 602 */                 validDateTime = CDateTimeComm.getAddDay(
/* 603 */                   crTime, validDay.intValue());
/*     */               }
/* 605 */               discount = ObjectComm.objectToDouble(rowMemberLevel.getValueOfName("discount"));
/*     */             }
/*     */ 
/* 611 */             Long groupId = ShopMap.getGroupIdOfShopId(shopId);
/* 612 */             String[] headMember = { "LevelID", 
/* 613 */               "DepositAmount", "IntegralAmount", 
/* 614 */               "ConsumeAmount", "CashCouponAmount", 
/* 615 */               "CouponAmount", "MemberID", "ShopID", 
/* 616 */               "groupId", "MemberCardNo", "ValidDay", 
/* 617 */               "DisCount", "ValidDateTime", 
/* 618 */               "IsCreateShop", "payPwd", "status", "CreateFileTime" };
/* 619 */             Object[] dataMember = { levelId, Integer.valueOf(0), intAmt, 
/* 620 */               Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), memberId, shopId, groupId, mp, 
/* 621 */               validDay, discount, validDateTime, Integer.valueOf(1), 
/* 622 */               "111111", Integer.valueOf(2), crTime };
/* 623 */             GsonHeadOneRow gMember = new GsonHeadOneRow(
/* 624 */               headMember, dataMember);
/* 625 */             gMember.encryptHead("payPwd");
/* 626 */             nResult = this.shopMemberDAO.insertGsonHeadOneRow(
/* 627 */               gMember, "crm_shop_member");
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 636 */         if (nResult > 0) {
/* 637 */           GsonHeadOneRow a = new GsonHeadOneRow(new String[] { 
/* 638 */             "ShopID", "OpenID", "custName", "Mp", "Status", 
/* 639 */             "CreateFileTime" }, new Object[] { shopId, openId, 
/* 640 */             custName, mp, Integer.valueOf(1), crTime });
/* 641 */           nResult = this.dao.insertGsonHeadOneRow(a, "crm_memberapply");
/*     */         }
/* 643 */         StringBuffer sb = new StringBuffer();
/* 644 */         sb.append("尊敬的" + custName + ",您已经通过会员审核。");
/* 645 */         if ((intAmt.intValue() > 0) && (nResult > 0)) {
/* 646 */           sb.append("本次获得" + intAmt + "积分。");
/*     */         }
/* 648 */         WeiXinUtil.sendTextMessageOfMain(sb.toString(), openId);
/*     */       }
/*     */     }
/*     */     else {
/* 652 */       if (StringUtils.isNotEmpty(mp)) {
/* 653 */         String num = StringUtils.substring(mp, 0, 7);
/* 654 */         if (StringUtils.isNotEmpty(num)) {
/* 655 */           String cityName = this.mpCityDAO.getCityName(num);
/* 656 */           if (StringUtils.isNotEmpty(cityName)) {
/* 657 */             r.addHeadData("cityName", cityName);
/*     */           }
/*     */         }
/*     */       }
/* 661 */       r.addHeadData(new String[] { "Status", "CreateFileTime" }, 
/* 662 */         new Object[] { Integer.valueOf(0), crTime });
/* 663 */       nResult = this.dao.insertGsonHeadOneRow(r);
/*     */     }
/* 665 */     return nResult;
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 681 */     String id = request.getParameter("id");
/* 682 */     String sDate = RequestUtils.getString(request, "data");
/*     */     try {
/* 684 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sDate);
/* 685 */       String status = null;
/* 686 */       Integer sys = null;
/* 687 */       if (g == null) {
/* 688 */         ResponseUtils.setErrorMsgResponse("请求错误", response);
/* 689 */         return;
/*     */       }
/* 691 */       status = (String)g.getValueOfName("Status");
/* 692 */       sys = ObjectComm.objectToInteger(g.getValueOfName("sys"));
/*     */ 
/* 694 */       GsonEbRst gsonStatus = this.dao.getSys(Long.valueOf(Long.parseLong(id)), null);
/* 695 */       if ((!(gsonStatus.isExistsData())) && (status == null)) {
/* 696 */         ResponseUtils.setErrorMsgResponse("请先启用会员卡", response);
/* 697 */         return;
/*     */       }
/*     */ 
/* 701 */       if ((status != null) && ("停用".equals(status))) {
/* 702 */         GsonEbRst gson = this.dao.getSys(Long.valueOf(Long.parseLong(id)), Boolean.valueOf(true));
/* 703 */         if (gson.isExistsData()) {
/* 704 */           ResponseUtils.setErrorMsgResponse("唯一默认入会，不可修改", response);
/* 705 */           return;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 711 */       if (sys != null) {
/* 712 */         if (sys.intValue() == 1) {
/* 713 */           this.dao.updateSysValueOfShopId(shopId);
/* 714 */         } else if (sys.intValue() == 0) {
/* 715 */           ResponseUtils.setErrorMsgResponse("唯一默认入会，不可修改", response);
/* 716 */           return;
/*     */         }
/*     */       }
/*     */ 
/* 720 */       int nResult = this.dao.updateJsonOneRow(g, id);
/* 721 */       if (nResult > 0) {
/* 722 */         GsonEbRst rst = getPtMemberLevelEdit(id, shopId, sDate, 
/* 723 */           response);
/* 724 */         if ((rst != null) && (rst.getState() == 0))
/* 725 */           DbConnection.commit();
/*     */         else {
/* 727 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 730 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 731 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 732 */         response);
/*     */     } catch (Exception e) {
/* 734 */       DbConnection.rollback();
/* 735 */       logger.error(e);
/* 736 */       ResponseUtils.setErrorMsgResponse(
/* 737 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 738 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private GsonEbRst getPtMemberLevelEdit(String id, Long shopId, String sDate, HttpServletResponse response) throws IOException
/*     */   {
/* 744 */     String sData = "data=" + sDate + "&" + "id" + 
/* 745 */       "=" + id;
/* 746 */     Long outId = ShopMap.getOutIdOfShopId(shopId);
/* 747 */     if ((outId != null) && (outId.longValue() > 0L)) {
/* 748 */       String sUrl = "ptMemlevel/edit/shopId/" + outId;
/* 749 */       GsonEbRst rst = HttpGsonPtResponseUtils.postPtEbRst(sUrl, sData, 
/* 750 */         response);
/* 751 */       if (rst != null) {
/* 752 */         return rst;
/*     */       }
/*     */     }
/* 755 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberWx.controller.MemberWxController
 * JD-Core Version:    0.5.3
 */